import {BasicColumn, FormSchema} from '/@/components/Table';
import {rules} from '/@/utils/helper/validator';
import {render} from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '商户名',
    width: 100,
    dataIndex: 'mchName',
    customRender: ({text}) => {
      return text
    }
  },
  {
    title: '商户号',
    width: 100,
    dataIndex: 'mchNo',
  },
  {
    title: '服务号',
    width: 80,
    dataIndex: 'isvNo',
  },

  {
    title: '状态',
    width: 60,
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = "green"
      if (text == '0') color = 'red'
      if (text == '1') color = 'green'
      
      return render.renderTag(render.renderDict(text, 'mch_status'), color)
    }
  },
  {
    title: '商户类型',
    width: 80,
    dataIndex: 'type',
    customRender: ({text}) => {
      let color = "cyan"
      if (text == '1') color = 'blue'
      if (text == '2') color = 'cyan'
      
      return render.renderTag(render.renderDict(text, 'mch_type'), color)
    }
  },
  {
    title: '创建时间',
    width: 150,
    dataIndex: 'createdAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'isvNo',
    label: '服务商号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'mchName',
    label: '商户名称',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    label: '商户状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'mch_status',
      placeholder:'请选择商户状态'
    },
    // colProps: {span: 6},
  },
  {
    label: '商户类型',
    field: 'type',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'mch_type',
      placeholder:'请选择商户类型'
    },
    // colProps: {span: 6},
  }
];


export const formDetailSchema = [
  {
    field: 'mchName',
    label: '商户名'
  },
  {
    field: 'mchNo',
    label: '商户号'
  },
  {
    field: 'isvNo',
    label: '服务号'
  },
  {
    field: 'type',
    label: '商户类型',
    render: (curVal, data) => {
      let color = "cyan"
      if (curVal == '1') color = 'blue'
      if (curVal == '2') color = 'cyan'
      
      return render.renderTag(render.renderDict(curVal, 'mch_type'), color)
    },
  },
  {
    field: 'contactName',
    label: '联系人姓名'
  },
  {
    field: 'contactTel',
    label: '联系人手机号'
  },
  {
    field: 'contactEmail',
    label: '联系人邮箱'
  },
  
  {
    field: 'status', 
    label: '状态',
    render: (curVal, data) => {
      let color = "green"
      if (curVal == '0') color = 'red'
      if (curVal == '1') color = 'green'
      
      return render.renderTag(render.renderDict(curVal, 'mch_status'), color)
    },
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'remark',
    label: '备注',
    labelMinWidth: 60
  }
  
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '',
    component: 'Input',
    show:false
  },
  {
    field: 'mchName',
    label: '商户名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'mchShortName',
    label: '商户简称',
    required: true,
    component: 'Input',
  },
  {
    field: 'contactName',
    label: '联系人姓名',
    required: true,
    component: 'Input',
  },
  {
    field: 'contactTel',
    label: '联系人手机号',
    required: true,
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { pattern: /^1[3|4|5|7|8|9][0-9]\d{8}$/, message: '手机号码格式有误' }
      ];
    },
  },
  {
    field: 'contactEmail',
    label: '联系人邮箱',
    component: 'Input',
    rules: rules.rule('email',false),
  },
  {
    field: 'status',
    label: '状态',
    component: 'JDictSelectTag',
    defaultValue: "1",
    componentProps: {
      dictCode:'mch_status',
      type:'radioButton'
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
  },
]
